<template>
  <div class="caseComp">
    <div class="caseCompTitle">编辑被投诉单位</div>
    <el-form
      :model="initInfo"
      :rules="rules"
      ref="ruleForm"
      label-width="100px"
    >
      <el-form-item label="单位名称" prop="complainedCompany">
        <el-input
          v-model="initInfo.complainedCompany"
          clearable=""
          placeholder="请输入"
          class="caseCompTitleInput"
        ></el-input>
      </el-form-item>
      <el-form-item label="行业" prop="industryName">
        <el-input
          v-model="initInfo.industryName"
          clearable=""
          placeholder="请输入"
          class="caseCompTitleInput"
        ></el-input>
      </el-form-item>
    </el-form>
    <div class="caseCompBtn">
      <el-button
        type="primary"
        v-sdc
        :loading="isLoading"
        class="commonBut saveBtn"
        @click="save"
        >保存</el-button
      >
      <el-button type="default" v-sdc class="commonBut" @click="finish"
        >取消</el-button
      >
    </div>
  </div>
</template>
<script>
export default {
  name: 'caseDepartment',
  props: {
    childData: {
      type: Object,
      required: true,
      default() {
        return {}
      },
    },
  },
  data() {
    return {
      isLoading: false,
      initInfo: {
        id: '',
        complainedCompany: '', //单位名称
        industryName: '', //项目性质
      },
      rules: {
        complainedCompany: [
          { message: '单位名称不能为空', trigger: 'blur' },
          { message: '最多输入20个字', trigger: 'blur', max: 20 },
        ],
        industryName: [
          { message: '行业不能为空', trigger: 'blur' },
          {
            message: '只能输入汉字',
            trigger: 'blur',
            pattern: /^[\u4e00-\u9fa5]+$/,
          },
          { message: '最多输入10个字', trigger: 'blur', max: 10 },
        ],
      },
    }
  },
  mounted() {
    this.initInfo = JSON.parse(JSON.stringify(this.childData))
  },

  methods: {
    save() {
      let params = this.initInfo
      delete params.createTime
      delete params.isDeleted
      delete params.effectiveStartDate
      delete params.effectiveEndDate
      delete params.creatorId
      delete params.updateTime
      delete params.updaterId
      this.$refs.ruleForm.validate((valid) => {
        if (valid) {
          this.axios
            .post('api-r/complaint/registration/edit', params)
            .then((res) => {
              if (!res.data.hasError) {
                this.$message({
                  type: 'success',
                  message: '修改成功',
                })
                this.isLoading = false
                this.finish(1)
              } else {
                this.$message({
                  type: 'warning',
                  message: res.data.errorMsg || '修改失败',
                })
                this.isLoading = false
              }
            })
        } else {
        }
      })
    },
    finish(index) {
      this.$emit('callback', { success: index == 1 ? true : false })
    },
  },
}
</script>
<style lang="less" scoped>
.caseComp {
  border: 1px solid #dcdfe6;
  background-color: #f8f9fb;
  padding: 15px;
  &Title {
    color: #009588;
    font-size: 14px;
    line-height: 30px;
    margin-bottom: 12px;
  }
  &List {
    line-height: 36px;
    height: 36px;
    font-size: 14px;
    color: #444;
    margin-bottom: 12px;
    &Title {
      display: inline-block;
      width: 85px;
      text-align: right;
    }
    &Input {
      width: calc(100% - 95px);
    }

    .input {
      width: calc(100% - 170px);
    }
  }
  &Btn {
    text-align: center;
    margin: 24px 0 10px;
    .el-button {
      width: 120px;
    }
  }
}
.caseCompListInput {
  width: calc(100%);
}
.caseCompListSelect {
  width: calc(100% - 95px);
}
</style>
